home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 2 / Apprentice-Release2.iso / Source Code / Mark Pilgrim / Kant Generator Pro 1.0.1 / source / kode new / kant build window.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-10-30  |  6.1 KB  |  255 lines  |  [TEXT/MMCC]

  1. #include "kant build window.h"
  2. #include "kant build meat.h"
  3. #include "kant build gui.h"
  4. #include "kant build files.h"
  5. #include "kant load-save.h"
  6. #include "environment.h"
  7. #include "util.h"
  8. #include "menus.h"
  9. #include "main.h"
  10. #include "dialogs.h"
  11. #include "text twiddling.h"
  12. #include "generic window handlers.h"
  13. #include "window layer.h"
  14. #include "program globals.h"
  15.  
  16. #define kGrowBoxSize        15
  17.  
  18. enum { key_LeftArrow=0x1c, key_RightArrow, key_UpArrow, key_DownArrow };
  19.  
  20. static    void PutDataIntoTEFields(WindowPtr theWindow);
  21.  
  22. static    short            gOldForegroundTime;        /* stored foreground wait time */
  23. static    Boolean            gIsActive=FALSE;
  24.  
  25. void SetupTheBuildWindow(WindowPtr theWindow)
  26. {
  27.     unsigned char    *titleStr="\puntitled";
  28.     Point            topLeft;
  29.     FSSpec            fs;
  30.     
  31.     SetWindowHeight(theWindow, 200);
  32.     SetWindowWidth(theWindow, qd.screenBits.bounds.right-qd.screenBits.bounds.left-70);
  33.     SetWindowType(theWindow, zoomDocProc);
  34.     topLeft.v=qd.screenBits.bounds.top+LMGetMBarHeight()+40;
  35.     topLeft.h=qd.screenBits.bounds.left+30;
  36.     SetWindowTopLeft(theWindow, topLeft);
  37.     SetWindowHasCloseBox(theWindow, TRUE);
  38.     SetWindowMaxDepth(theWindow, 1);
  39.     SetWindowDepth(theWindow, 1);
  40.     SetWindowIsFloat(theWindow, FALSE);
  41.     SetWindowTitle(theWindow, titleStr);
  42.     SetWindowAutoCenter(theWindow, FALSE);
  43.     fs.name[0]=0x00;
  44.     fs.vRefNum=0;
  45.     fs.parID=0;
  46.     SetWindowFS(theWindow, fs);
  47.     SetWindowIsModified(theWindow, FALSE);
  48. }
  49.  
  50. void OpenTheBuildWindow(WindowPtr theWindow)
  51. {
  52.     TEHandle        hTE;
  53.     FontInfo        theFontInfo;
  54.     Rect            vScrollBarRect, hScrollBarRect;
  55.     Rect            destRect, viewRect;
  56.     
  57.     hTE=GetWindowTE(theWindow);
  58.     if (hTE==0L)
  59.     {
  60.         SetRect(&vScrollBarRect, GetWindowWidth(theWindow)-kGrowBoxSize, -1,
  61.             GetWindowWidth(theWindow)+1, GetWindowHeight(theWindow)+1-kGrowBoxSize);
  62.         SetRect(&hScrollBarRect, -1, GetWindowHeight(theWindow)-kGrowBoxSize,
  63.             GetWindowWidth(theWindow)-kGrowBoxSize+1, GetWindowHeight(theWindow)+1);
  64.         SetWindowVScrollBar(theWindow,
  65.             NewControl(theWindow, &vScrollBarRect, "\p", TRUE, 0, 0, 0, scrollBarProc, 0));
  66.         SetWindowHScrollBar(theWindow,
  67.             NewControl(theWindow, &hScrollBarRect, "\p", TRUE, 0, 0, 5000, scrollBarProc, 0));
  68.         
  69.         GetTERect(theWindow, &destRect, TRUE);
  70.         viewRect=destRect;
  71.         destRect.right+=5000;
  72.         hTE=TENew(&destRect, &viewRect);
  73.         SetWindowTE(theWindow, hTE);
  74.         TextFont((**hTE).txFont=geneva);
  75.         TextSize((**hTE).txSize=9);
  76.         TextFace((**hTE).txFace=0);
  77.         GetFontInfo(&theFontInfo);
  78.         (**hTE).fontAscent=theFontInfo.ascent;
  79.         (**hTE).lineHeight=theFontInfo.ascent+theFontInfo.descent+theFontInfo.leading;
  80.         AdjustViewRect(hTE);
  81.         TEAutoView(TRUE, hTE);
  82.         TESetClickLoop((ProcPtr)MyClikLoop, hTE);
  83.         PutDataIntoTEFields(theWindow);
  84.     }
  85.     
  86.     gIsActive=TRUE;
  87.     AdjustVScrollBar(GetWindowVScrollBar(theWindow), hTE);
  88.     AdjustMenus();
  89. }
  90.  
  91. void KeyPressedInBuildWindow(WindowPtr theWindow, unsigned char theChar)
  92. {
  93.     TEHandle        hTE;
  94.     ControlHandle    vScrollBar;
  95.     short            lineNum;
  96.     
  97.     hTE=GetWindowTE(theWindow);
  98.     vScrollBar=GetWindowVScrollBar(theWindow);
  99.     
  100.     switch (theChar)
  101.     {
  102.         case key_UpArrow:
  103.             if (AnyHighlightedQQ(theWindow))
  104.             {
  105.                 lineNum=CurrentLineNumber(hTE);
  106.                 if (lineNum==0)
  107.                     lineNum=TotalNumberOfLines(hTE)-1;
  108.             }
  109.             else lineNum=TotalNumberOfLines(hTE)-1;
  110.             
  111.             HighlightLine(hTE, lineNum-1);
  112.             break;
  113.         case key_DownArrow:
  114.             if (AnyHighlightedQQ(theWindow))
  115.             {
  116.                 lineNum=CurrentLineNumber(hTE);
  117.                 if (lineNum==TotalNumberOfLines(hTE)-2)
  118.                     lineNum=-1;
  119.             }
  120.             else lineNum=-1;
  121.             
  122.             HighlightLine(hTE, lineNum+1);
  123.             break;
  124.         case '\r':
  125.             if (RefHighlightedQQ(theWindow))
  126.                 DoEditRef(theWindow);
  127.             else
  128.                 DoEditInstantiation(theWindow);
  129.             break;
  130.         case 0x08:
  131.             if (RefHighlightedQQ(theWindow))
  132.                 DoDeleteRef(theWindow);
  133.             else
  134.                 DoDeleteInstantiation(theWindow);
  135.             break;
  136.         default:
  137.             break;
  138.     }
  139.     
  140.     AdjustVScrollBar(vScrollBar, hTE);
  141. }
  142.  
  143. Boolean MouseClickedInBuildWindow(WindowPtr theWindow, Point thePoint)
  144. {
  145.     short            partCode;
  146.     ControlHandle    theControl;
  147.     short            scrollDistance;
  148.     short            oldSetting;
  149.     ControlActionUPP    scrollActionUPP=NewControlActionProc(ScrollActionProc);
  150.     ControlActionUPP    hScrollActionUPP=NewControlActionProc(HScrollActionProc);
  151.     TEHandle        hTE;
  152.     
  153.     if (gInProgress)
  154.         return TRUE;
  155.     
  156.     hTE=GetWindowTE(theWindow);
  157.     
  158.     if (PtInRect(thePoint, &((**hTE).viewRect)))
  159.     {
  160.         DealWithBuildContentClick(theWindow, thePoint);
  161.         return TRUE;
  162.     }
  163.     else
  164.     {
  165.         partCode=FindControl(thePoint, theWindow, &theControl);
  166.         if (theControl==GetWindowVScrollBar(theWindow))
  167.         {
  168.             switch (partCode)
  169.             {
  170.                 case inThumb:
  171.                     oldSetting=GetControlValue(theControl);
  172.                     partCode=TrackControl(theControl, thePoint, 0L);
  173.                     if (partCode==inThumb)
  174.                     {
  175.                         scrollDistance=oldSetting-GetControlValue(theControl);
  176.                         if (scrollDistance!=0)
  177.                             TEPinScroll(0, scrollDistance*(**hTE).lineHeight, hTE);
  178.                     }
  179.                     break;
  180.                 case inUpButton:
  181.                 case inDownButton:
  182.                 case inPageUp:
  183.                 case inPageDown:
  184.                     partCode=TrackControl(theControl, thePoint, scrollActionUPP);
  185.                     break;
  186.             }
  187.             
  188.             return TRUE;
  189.         }
  190.         else if (theControl==GetWindowHScrollBar(theWindow))
  191.         {
  192.             switch (partCode)
  193.             {
  194.                 case inThumb:
  195.                     oldSetting=GetControlValue(theControl);
  196.                     partCode=TrackControl(theControl, thePoint, 0L);
  197.                     if (partCode==inThumb)
  198.                     {
  199.                         scrollDistance=oldSetting-GetControlValue(theControl);
  200.                         if (scrollDistance!=0)
  201.                             TEPinScroll(scrollDistance, 0, hTE);
  202.                     }
  203.                     break;
  204.                 case inUpButton:
  205.                 case inDownButton:
  206.                 case inPageUp:
  207.                 case inPageDown:
  208.                     partCode=TrackControl(theControl, thePoint, hScrollActionUPP);
  209.             }
  210.         }
  211.     }
  212.     
  213.     return FALSE;
  214. }
  215.  
  216. void DisposeTheBuildWindow(WindowPtr theWindow)
  217. {
  218.     TEHandle        hTE;
  219.     
  220.     hTE=GetWindowTE(theWindow);
  221.     if (hTE!=0L)
  222.     {
  223.         TEDispose(hTE);
  224.         SetWindowTE(theWindow, 0L);
  225.     }
  226. }
  227.  
  228. void ActivateTheBuildWindow(WindowPtr theWindow)
  229. {
  230.     gOldForegroundTime=gForegroundWaitTime;
  231.     gForegroundWaitTime=0;
  232.     gIsActive=TRUE;
  233. }
  234.  
  235. void DeactivateTheBuildWindow(WindowPtr theWindow)
  236. {
  237.     gForegroundWaitTime=gOldForegroundTime;
  238.     gIsActive=FALSE;
  239. }
  240.  
  241. void CopybitsTheBuildWindow(WindowPtr theWindow, WindowPtr offscreenWindow)
  242. {
  243.     GenericCopybits(theWindow, offscreenWindow, gIsActive);
  244. }
  245.  
  246. static    void PutDataIntoTEFields(WindowPtr theWindow)
  247. {
  248.     TEHandle        hTE;
  249.     
  250.     hTE=GetWindowTE(theWindow);
  251.     TESetSelect(0, 0, hTE);
  252.     TEKey(0x00, hTE);
  253.     TEKey(0x08, hTE);
  254. }
  255.